package Song.Han.demo05;

public class ChiHuo extends Thread {
    //1.需要在成员位置创建一个包子变量
    private BaoZi baoZi;

    //2.使用带参构造
    public ChiHuo(BaoZi bz) {
        this.baoZi = bz;
    }

    @Override
    public void run() {
        while (true) {
            synchronized (baoZi) {
                if (baoZi.flag == false) {
                    try {
                        baoZi.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                //被唤醒后，开始吃
                System.out.println("正在吃" + baoZi.pi + baoZi.xian + "包子");
                //吃完后,唤醒包子铺线程。生产包子
                baoZi.flag = false;
                baoZi.notify();
                System.out.println("吃货吃完，包子铺开始生产");
                System.out.println("--------------------------------");
            }

        }
    }
}
